package net.xuhf.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/")
public class UserController {

    @GetMapping("/doLogin")
    public String doLogin(String username, String password) {
        if ("zhang".equals(username) && "1".equals(password)) {
            StpUtil.login(100001);

            return "登录成功";
        }
        return "登录失败";
    }

    @GetMapping("/isLogin")
    public String isLogin() {
        return "当前是否登录" + StpUtil.isLogin();
    }

    @GetMapping("/tokenInfo")
    public SaResult tokenInfo() {
        return SaResult.data(StpUtil.getTokenInfo());
    }

    @GetMapping("/logout")
    public SaResult logout() {
        StpUtil.logout();
        return SaResult.ok();
    }

}
